<?php
namespace app\index\Controller;

use app\common\controller\Base;
use think\facade\Session;
use think\facade\Request;
use think\Db;

class Message extends Base
{
	//消息
	public function nums(){

            //$res['status'] = 0;
			$res=['status' =>0,'count' => 0, 'msg' => 'nums'];
        
        return $res;
	}

	//文章收藏
	public function add(){
		//$data = Request::param();
		$data['article_id'] = intval(input('cid'));
		$data['user_id'] = session::get('user_id');
		$result = CollectionModel::create($data);
        if($result){
            $res['status'] = 0;
			//$res=['type' => 'add','type' => 'remove', 'msg' => '收藏成功'];
        }
        return $res;
	}

    //取消收藏
    public function remove(){
		
		$cid = input('cid');
        $arid = intval($cid);

        //$result = CollectionModel::where('cid',$arid)->select();
        $result =  Db::name('collection')->where('article_id',$arid)->delete();
        if($result){
            //$res=['type' => 'add','type' => 'remove', 'msg' => '收藏成功'];
            $res = [
                'status' => 0,
            ];
           
        }
	 return $res;
    }

    //收藏查询
	public function find(){
		//$cid = Request::param();
		$cid = input('cid');
		$artid = intval($cid);
        $collectData =  Db::name('collection')->where('article_id',$artid)->find();
		if($collectData){
			$res['status'] = 0;
			$res['data']['collection'] = $collectData['article_id'];
			//$collect = Collection::where('article_id',$artid)->order('create_time','desc')->select();
			//$this->assign('collect',$collect);
			//return view('index/user/index');
		} else {
			$res['status'] = 0;
			$res['data'] = '';
		}
        
       return json($res);
	}

	
}